<?php

class ImgAction extends Action {

    /**
     * 汽车版本
     */
    public function index($ClassID = 0,$pageSize = 10,$page = 0){

        $stypeArr = C(IMG_NAV);
        $ClassID = $stypeArr[$ClassID]['VALUE'];

        $DataPhoto = $this-> searchImg($ClassID,$pageSize,$page);

        $this->assign('ClassID',$ClassID);
        $this->assign('DataPhoto',$DataPhoto);
        $this->display();
     }

    /**
     * 浏览图片详情
     * @param $imgClassID
     */
    public function imgdes($imgClassID){
            $Model = new Model(); // 实例化一个model对象 没有对应任何数据表
            $StrSqlPhotoClass = "SELECT * FROM photo_class where id = ".$imgClassID." ";
            $DataPhotoClass= $Model->query( $StrSqlPhotoClass );
                if($DataPhotoClass){
                    $StrSqlPhoto ="SELECT *,ROW_NUMBER() OVER (ORDER BY id asc) AS RowNumber FROM photo where classid = ".$imgClassID." ORDER BY id asc";
                    $DataPhoto= $Model->query( $StrSqlPhoto );

                    //随机4个
                    $StrRanThree =  "select top 4 *, NewID() as random from (SELECT top 20 * FROM photo_class where Dth = 3 and area_name = '".C('APP_URL_AREA')."' ORDER BY id desc) pc2 order by random  ";
                    $DataRanThree= $Model->query( $StrRanThree );

                    $this->assign('DataRanThree',$DataRanThree);
                    $this->assign('DataPhotoClass',$DataPhotoClass);
                    $this->assign('DataPhoto',$DataPhoto);

                    $this->display();
                }else{
                    $this->error('没有找到该图片集！');
                }
    }

    /**
     * JSONP返回更多图片
     * @param $ClassID
     * @param int $pageSize
     * @param int $page
     */
    public function moreImg($ClassID = 0,$pageSize = 20,$page = 0){

        $stypeArr = C(IMG_NAV);
        $ClassID = $stypeArr[$ClassID]['VALUE'];

        $DataPhoto = $this-> searchImg($ClassID,$pageSize,$page);
        if ($DataPhoto){
            $this->ajaxReturn($DataPhoto,"查询成功！",1);
        }else{
            $this->ajaxReturn(0,"没有数据了！",0);
        }
    }

    /**
     * 图片搜索
     * @param $ClassID
     * @param int $pageSize
     * @param int $page
     * @return array|mixed
     */
    public function  searchImg($ClassID, $pageSize = 10,$page = 0){

        $stypeArr = C(IMG_NAV);
        $ClassID = $stypeArr[$ClassID]['VALUE'];
        $where = "";

        switch ( $ClassID ) {
            case  0 :
                $where = "SELECT id from photo_class where pclassid in (SELECT id from photo_class where pclassid in (SELECT id from photo_class where id in(26,31)) and id not in (32,42,41,1655) )";
                break;
            case  1 :
                $where = "SELECT id from photo_class where pclassid in (SELECT id from photo_class where pclassid in (SELECT id from photo_class where id in(31)) and id not in (32,42,41,1655) )";
                break;
            case  2 :
                $where = "SELECT id from photo_class where pclassid in (SELECT id from photo_class where pclassid in (SELECT id from photo_class where id in(31)) and id not in (32,58,41,1655) )";
                break;
            case  3 :
                $where = "SELECT id from photo_class where pclassid in (SELECT id from photo_class where pclassid in (SELECT id from photo_class where id in(31)) and id not in (32,58,42,1655) )";
                break;
            case  4 :
                $where = "SELECT id from photo_class where pclassid in (SELECT id from photo_class where pclassid in (SELECT id from photo_class where id in(31)) and id not in (32,58,42,41) )";
                break;
            case  5 :
                $where = "68";
                break;
            case  6 :
                $where = "54,1298";
                break;
            case  7 :
                $where = "SELECT id from photo_class where pclassid in (SELECT id from photo_class where pclassid in (SELECT id from photo_class where id in(81)) and id not in (82) )";
                break;
            default :
                $where = "SELECT id from photo_class where pclassid in (SELECT id from photo_class where pclassid in (SELECT id from photo_class where id in(26,31)) and id not in (32,42,41,1655) )";
                break;
        }



        $Model = new Model(); // 实例化一个model对象 没有对应任何数据表
        $StrSqlPhoto ="SELECT * from (select top ".intval($pageSize)*(intval($page)+1)." * from photo_class pc LEFT JOIN (select p.classid,CONVERT(varchar(100), min(p.date), 120) as DateAndTime,min(p.small_pic) as small_pic,min(p.big_pic) as big_pic,min(p.big_big_pic) as big_big_pic from photo  p GROUP BY p.classid ) p  on p.classid = pc.id where pclassid in (".$where.") and pc.area_name='".C("APP_URL_AREA")."' ORDER BY id DESC ) as art where  art.id not in (select top ".intval($pageSize)*intval($page)." ID from photo_class pc LEFT JOIN (select p.classid,CONVERT(varchar(100), min(p.date), 120) as DateAndTime,min(p.small_pic) as small_pic,min(p.big_pic) as big_pic,min(p.big_big_pic) as big_big_pic from photo  p GROUP BY p.classid ) p  on p.classid = pc.id where pclassid in (".$where.") and pc.area_name='".C("APP_URL_AREA")."' ORDER BY id DESC )";
        $DataPoto= $Model->query( $StrSqlPhoto );
        return $DataPoto;
    }


}